$(function(){
	var swiper = new Swiper('.swiper-container', {
	      observer:true,//修改swiper自己或子元素时，自动初始化swiper  
          observeParents:true,//修改swiper的父元素时，自动初始化swiper  
	      pagination: {
	        el: '.swiper-pagination',
	      },
	      on: {
	    	    init: function(){
    				mswiper(1,"search",4,"swiper");
	    	    },
	      }
	      
	    });
	swiper.on('touchEnd', function () {
		if(this.isEnd){
			var page;
			page=(this.activeIndex)+2;
			mswiper(page,"search",4,"swiper");
		}
		
		});
	
	 
			 
});
        	
function mswiper(page,search,pageSize,classId){
	var search = $('#'+search).val();
	$.ajax({
		url: "/examReport/findAchievementStatistics",
		type: "POST",
		data: {
            pageNo: page,
            pageSize: pageSize,
            search: search
        },
        dataType: 'json',
		success: function(data){
			
			var result = '';
			var div=$('<div class="swiper-slide"></div>');
			var arrLen = data.length;
			if (arrLen > 0) {
				for (var i = 0; i < arrLen; i++) {
					result += '<div class="grade-cjtj" id="'+data[i].id+'">'
							+'<div class="paper-a">试卷名称:'+data[i].name+'</div>'
							+'<div class="paper-b">试卷类型:'+data[i].examType
							+'<span>总分:'+data[i].totalScore+'</span>'
							+'<span>人员数量:'+data[i].totalPeople+'</span>'
							+'<span>合格率:'+data[i].qrate+'%</span>'
							+'</div>'
							+'<div class="documentation-check"></div>'
							+'</div>';
					
				} 
				div.append(result);
				$('#' + classId).append(div);
				 //成绩统计
			    $('.grade-cjtj').on('click', function() {
			    	 $(".grade-cjtj").removeClass("active");
				     $(this).addClass("active");
					 var paperId=$(this).attr("id");
					 commajax(paperId);
				 });
			    $(".grade-cjtj").eq(0).trigger('click');//默认选中第一个
		}
	}
});
}
function js_method(){
	$("#swiper").empty();
	mswiper(1,"search",4,"swiper");
}
function commajax(paperId){
	var chartOptions ={
			chart: {
	        	 plotShadow: false,
	             type: 'pie'
	        },
	        title: {
	            text: '<b>成绩分布</b>'
	        },
	        tooltip: {
	            pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>'
	        },
	        plotOptions: {
	            pie: {
	                allowPointSelect: true,
	                cursor: 'pointer',
	                dataLabels: {
	                    enabled: true,
	                    format: '{point.name}: <b>{point.y}</b>'
	                },
	                showInLegend: true
	            }
	        }
		};
	var chartOptions2={
			chart: {
	            type: 'column'
	        },
	        title: {
	            text: '<b>平均分</b>'
	        },
	        yAxis: {
	            min: 0,
	            title: {
	                text: '分数'
	            }
	        },
	        tooltip: {
	            headerFormat: '<span style="font-size:10px">{point.key}</span><table>',
	            pointFormat: '<tr><td style="color:{series.color};padding:0">{series.name}: </td>' +
	                '<td style="padding:0"><b>{point.y:.1f} 分</b></td></tr>',
	            footerFormat: '</table>',
	            shared: true,
	            useHTML: true
	        },
	        plotOptions: {
	            column: {
	                pointPadding: 0.2,
	                borderWidth: 0
	            }
	        }
	}
	var socreline={
			 name: '百分比',
	         colorByPoint: true,
			 data:new Array()
	};
	var socreline2={
			name: '平均分',
            color:'#3db9d3',
			data:new Array()
	};
	
	var xAxis={
        categories:new Array(),
        crosshair: true
    }
	$.ajax({
		url: "/examReport/achievementDistribution",
		type: "POST",
		data: {"paperId": paperId},
		success: function(v){
			socreline.data=[];
			socreline.data.push(['得分小于总分50%不及格',parseInt(v.grade1)]);
			socreline.data.push(['得分为总分的50%-60%不及格',parseInt(v.grade2)]);
			socreline.data.push(['得分为总分的60%-70%及格',parseInt(v.grade3)]);
			socreline.data.push(['得分为总分的70%-85%良',parseInt(v.grade4)]);
			socreline.data.push(['得分为总分的85%-100%优',parseInt(v.grade5)]);
			chartOptions.series=[socreline];
			var chart = new  Highcharts.Chart('container',chartOptions);
			socreline2.data=[];
			xAxis.categories=[];
			$.each(v.userGroupStatisticsList,function(index,element){
				socreline2.data.push(parseFloat(element["pscore"]));
				xAxis.categories.push(element["name"]);
			});
			chartOptions2.series=[socreline2];
			chartOptions2.xAxis=[xAxis];
			var chart2 = new  Highcharts.Chart('containera',chartOptions2);
		}
	});
}